<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
	version="1.0"
	xmlns:php="http://php.net/xsl"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
		
	<xsl:include href="../main.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="../common/navigation.xsl" />
	<xsl:include href="blocks.xsl" />
	<xsl:include href="../users/ownerBar.xsl" />
	
	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/photos/photos.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/owner-bar.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/photos.js" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />
			
			<div class="page-header">
				<xsl:call-template name="logo" />
				
				<xsl:call-template name="menu" />
			</div>
			
			<div class="page-content-wrapper">	
				<div class="page-blocks">
					<xsl:call-template name="default-blocks-top" />
					
					<div class="block">
						<div class="header">Облако тегов</div>
						<div class="content tags">
							<xsl:apply-templates select="document('xmodule://photos/getTagsCloud')/data/response/tags" mode="block-tags-cloud" />
						</div>
						
						<i class="corner-f8-10 tl"></i>
						<i class="corner-f8-10 tr"></i>
						<i class="corner-f8-10 br"></i>
						<i class="corner-f8-10 bl"></i>
					</div>
				</div>
			
				<div class="page-content">
					<xsl:apply-templates select="response" />
				</div>
			</div>
			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	
	<xsl:template match="response">
		<xsl:if test="../@method = 'user'">
			<xsl:apply-templates select="document(concat('xmodule://users/getUser/', @user-id))/data/response/object[@type='user']" mode="ownerbar" />
		</xsl:if>
		<xsl:if test="../@method != 'user'">
			<h1>Фотоальбомы</h1>
		</xsl:if>
			
		<xsl:if test="count(object) = 0">
			<div class="simple-message">
				<xsl:text>Фотоальбомов не найдено.</xsl:text>
				<xsl:if test="../@method = 'user' and @user-id = $userId">
					<xsl:text> </xsl:text>
					<input type="button" value="Создать новый" onclick="document.location.href='{$baseURI}/photos/create_album'" />
				</xsl:if>
			</div>
		</xsl:if>
		
		<xsl:if test="count(object) != 0">
			<div class="photoalbums-list">
				<xsl:apply-templates select="object">
					<xsl:with-param name="userId" select="../@user-id" />
					<xsl:with-param name="userGroup" select="../@user-group" />
				</xsl:apply-templates>
			</div>
			
			<xsl:apply-templates select="pages" mode="pages-navigation">
				<xsl:with-param name="href">
					<xsl:choose>
						<xsl:when test="../@method = 'user'">
							<xsl:value-of select="concat ($baseURI, '/photos/user/', @user-login)" />
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$baseURI" />
							<xsl:text>/photos</xsl:text>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:with-param>
			</xsl:apply-templates>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="object[@type='photoalbum']">
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		
		<div class="item">
			<div class="preview">
				<a href="{$baseURI}/photoalbum/{@id}">
					<img>
						<xsl:attribute name="src">
							<xsl:choose>
								<xsl:when test="property[@name='preview']/value = ''">
									<xsl:value-of select="$baseURI" />
									<xsl:text>/images/default-photoalbum-preview.png</xsl:text>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="concat ($baseURI, '/thumb_75_75', property[@name='preview']/value)" />
								</xsl:otherwise>
							</xsl:choose>
						</xsl:attribute>
						<xsl:attribute name="alt">
							<xsl:value-of select="property[@name='title']/value" />
						</xsl:attribute>
					</img>
				</a>
			</div>
			<div class="info">
				<div class="title">
					<a href="{$baseURI}/photoalbum/{@id}">
						<xsl:value-of select="property[@name='title']/value" />
					</a>
				</div>
				
				<div class="stat">
					<p>
						<xsl:text>Создан </xsl:text>
						<xsl:value-of select="property[@name='date']/birthdate" />
						<br />
						<xsl:text>Обновлен </xsl:text>
						<xsl:value-of select="property[@name='update']/birthdate" />
					</p>
					<p>
						<xsl:value-of select="php:functionString ('XSLTGetNumWithCase', property[@name='count_photos']/value, 'фотография', 'фотографии', 'фотографий')" />
					</p>
				</div>
				
				<div class="description">
					<xsl:value-of select="property[@name='description']/value" />
				</div>

				<xsl:if test="property[@owner_id]/value = $userId or $userGroup = 'admin' or $userGroup = 'moderator'">				
					<div class="controls">
						<a href="{$baseURI}/photos/edit_album/{@id}">редактировать</a>
						<a onclick="if(!confirm('Вы действительно хотите удалить этот фотоальбом?'))return false;" href="{$baseURI}/photos/delete_album/{@id}">удалить</a>
					</div>
				</xsl:if>
			</div>
		</div>
	</xsl:template>
	
</xsl:stylesheet>